<template>
	<div class="system-role-container">
		<el-card shadow="hover">
			<div class="system-user-search mb15">
        <el-form :inline="true">
          <!-- <el-form-item label="角色名称">
            <el-input size="default" v-model="tableData.param.roleName" placeholder="请输入角色名称" class="w-50 m-2" clearable/>
          </el-form-item> -->
          <el-form-item label="筛选">
            <el-select size="default" placeholder="请选择会员类型" class="w-50 m-2" v-model="tableData.param.roleStatus" clearable>
              <el-option label="ID"  value="0" />
              <!-- <el-option label="会员账号"  value="1" />
			  <el-option label="代理会员"  value="2" />
			  <el-option label="是否在线"  value="3" /> -->
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button size="default" type="primary" class="ml10" @click="roleList">
              <el-icon>
                <ele-Search />
              </el-icon>
              查询
            </el-button>
            <el-button size="default" type="success" class="ml10" @click="onOpenAddRole">
              <el-icon>
                <ele-FolderAdd />
              </el-icon>
              新增会员等级
            </el-button>
			<el-button size="default" type="primary" class="ml10" @click="Refresh">
				<!-- <el-icon><Refresh /></el-icon> -->
              刷新页面
            </el-button>
			
          </el-form-item>
        </el-form>
			</div>
			<el-table :data="tableData.data" style="width: 100%">
				<!-- <el-table-column type="index" label="ID
" width="60" /> -->
			<el-table-column fixed prop="Member_id" label="ID" show-overflow-tooltip></el-table-column>
				<el-table-column prop="Member_account" label="等级名称" width="100" ></el-table-column>
				<el-table-column prop="Name" label="充值累计" show-overflow-tooltip></el-table-column>
				<!-- <el-table-column prop="status" label="等级" show-overflow-tooltip>
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.status===1">启用</el-tag>
						<el-tag type="info" v-else>禁用</el-tag>
					</template>
				</el-table-column> -->
				<el-table-column prop="grade" label="流水累计" show-overflow-tooltip></el-table-column>
				<el-table-column prop="Whether_agent" label="比例1" show-overflow-tooltip></el-table-column>
        <el-table-column prop="balance" label="比例2" show-overflow-tooltip></el-table-column>
		<el-table-column prop="Points_balance" label="比例3" show-overflow-tooltip></el-table-column>

		<el-table-column prop="state" label="状态" show-overflow-tooltip></el-table-column>
		<el-table-column prop="Game_balance" label="对应图片" show-overflow-tooltip></el-table-column>
		
		<el-table-column prop="Creation_time" label="创建时间" show-overflow-tooltip></el-table-column>
				<el-table-column label="操作" width="300">
					<template #default="scope">
						<el-button size="small" text type="primary" @click="onOpenEditRole(scope.row)"><el-icon><ele-EditPen /></el-icon>修改</el-button>
						<el-button size="small" text type="primary" @click="onRowDel(scope.row)"><el-icon><ele-DeleteFilled /></el-icon>删除</el-button>
						<!-- <el-button size="small" text type="primary" @click="Adjusting_Balanceaon"><el-icon><ele-EditPen /></el-icon>显示</el-button> -->
					</template>
				</el-table-column>
	
			</el-table>
      <!-- <pagination
          v-show="tableData.total>0"
          :total="tableData.total"
          v-model:page="tableData.param.pageNum"
          v-model:limit="tableData.param.pageSize"
          @pagination="roleList"
      /> -->
		</el-card>
		<!-- <EditRole ref="editRoleRef" @getRoleList="roleList"/> -->
        <MemberListadd ref="editRoleRef" @getRoleList="roleList"/>
		<Adjusting_Balance ref="Adjusting" @getRoleList="roleList"/>
	</div>
</template>

<script lang="ts">
import {toRefs, reactive, onMounted, ref, defineComponent, toRaw,getCurrentInstance} from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import MemberListadd from './component/berListadd.vue';
import Adjusting_Balance from './component/Adjusting_balance.vue'; 
import {deleteRole, getRoleList} from "/@/api/MemberManagement/MemberList";
// 定义接口来定义对象的类型
interface TableData {
	Member_id:number;
	Member_account: number;
	grade: number;
	Name: string;
	Whether_agent: boolean;
	balance:number;
	Points_balance: number;
	Last_login_IP:number;
	Creation_time:number;
	Accumulated_recharge:number;
	state:boolean;
	Game_balance:number;
}
interface TableDataState {
	tableData: {
		data: Array<TableData>;
		total: number;
		loading: boolean;
		param: {
      roleName:string;
      roleStatus:string;
			pageNum: number;
			pageSize: number;
		};
	};
}

export default defineComponent({
	name: 'apiV1SystemRoleList',
	components: {MemberListadd,Adjusting_Balance},
	setup() {
    const {proxy} = getCurrentInstance() as any;
		const addRoleRef = ref();
		const editRoleRef = ref();
		const Adjusting = ref();
    const dataScopeRef =ref();
		const state = reactive<TableDataState>({
			tableData: {
				data: [],
				total: 0,
				loading: false,
				param: {
          roleName:'',
          roleStatus:'',
					pageNum: 1,
					pageSize: 10,
				},
			},
		});
	
		// 初始化表格数据
		const initTableData = () => {
			roleList()
		};
    const roleList = ()=>{
      const data: Array<TableData> = [];
      getRoleList(state.tableData.param).then(res=>{
        const list = res.data.list??[]
        list.map((item:TableData)=>{
        //   data.push({
        //     id:item.id,
        //     status: item.status,
        //     listOrder: item.listOrder,
        //     name: item.name,
        //     remark: item.remark,
        //     dataScope:item.dataScope,
        //     createdAt: item.createdAt,
        //   });
        })
        state.tableData.data = data;
        state.tableData.total = res.data.total;
      })
    };
		// 打开新增角色弹窗
		const onOpenAddRole = () => {
      editRoleRef.value.openDialog();
		};
		// 打开修改角色弹窗
		const onOpenEditRole = (row: Object) => {
			editRoleRef.value.openDialog(toRaw(row));
		};
// 调整余额
const Adjusting_Balanceaon = () => {
	Adjusting.value.openDialoga();
		};
		// 删除角色
		const onRowDel = (row: any) => {
			ElMessageBox.confirm(`此操作将永久删除角色：“${row.name}”，是否继续?`, '提示', {
				confirmButtonText: '确认',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
          deleteRole(row.id).then(()=>{
            ElMessage.success('删除成功');
            proxy.$refs['editRoleRef'].resetMenuSession();
            roleList();
          })
				})
				.catch(() => {});
		};
        	// 刷新页面
		const Refresh = (row: Object) => {
			console.log("刷新页面")
		};
		
		// 分页改变
		const onHandleSizeChange = (val: number) => {
			state.tableData.param.pageSize = val;
		};
		// 分页改变
		const onHandleCurrentChange = (val: number) => {
			state.tableData.param.pageNum = val;
		};
		// 页面加载时
		onMounted(() => {
			// initTableData();
	
	state.tableData.data.push({
			Member_id:1,
	Member_account: 23,
	grade: 3,
	Name: '理想玩',
	Whether_agent: true,
	balance:1,
	Points_balance: 2,
	Last_login_IP:3,
	Creation_time:4,
	Accumulated_recharge:999,
	state:true,
	Game_balance:11
          });
	
        })
      
		return {
			Adjusting,
			addRoleRef,
			editRoleRef,
     		 dataScopeRef,
			onOpenAddRole,
			onOpenEditRole,
			onRowDel,
			onHandleSizeChange,
			onHandleCurrentChange,
      roleList,
      Refresh,
	  Adjusting_Balanceaon,
			...toRefs(state),
		};
	},
});
</script>
